package com.iraeta.common;

import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;

public class MySessionManager {
    private static final TimedCache<String, MySession> timedCache = CacheUtil.newTimedCache(30 * 60 * 1000); //默认30分钟过期
    static {
        timedCache.schedulePrune(10000);    //每10秒检查一次过期
    }

    public static MySession get(String key) {
        MySession mySession = timedCache.get(key);
        if(mySession == null){
            mySession=new MySession();
            timedCache.put(key, mySession);
        }
        return timedCache.get(key);
    }

    public static void remove(String key){
        timedCache.remove(key);
    }
}
